// pages/goods_list/goods_list.js
import {
  request
} from '../../request/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodslist: [],

    tabs: [{
        id: 0,
        value: '综合',
        isActive: true
      },
      {
        id: 1,
        value: '销量',
        isActive: false
      },
      {
        id: 2,
        value: '价格',
        isActive: false
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {
      id
    } = options
    console.log(id);
    this.getgoodlist(id)
  },

  getgoodlist(id) {
    request({
      url: '/goods/search',
      data: {
       cid: id
      }
    }).then(res => {
      console.log(res);
      this.setData({
        goodslist: res
      })
    })
  },

  handleTabsItemChange(e) {
    //获取被点击事件的索引
    const {
      index
    } = e.detail;
    //修改原数组;
    let {
      tabs
    } = this.data;
    tabs.forEach((v, i) => {
      i === index ? v.isActive = true : v.isActive = false
    })
    this.setData({
      tabs
    })
  },
})